package com.dduggs.note.thread.threadtest2;

/**
 * Created by ChenJiasheng on 2017/10/24.
 */
class MyThread2 implements Runnable{

    private int ticketsCount = 5;//一共有5张火车票

    @Override
    public void run() {
        while (ticketsCount>0){
            ticketsCount--;
            System.out.println(Thread.currentThread().getName()+"卖了一张票，还剩"+ticketsCount+"张票");
        }
    }
}

public class TicketsRunnable{
    public static void main(String[] args) {

        MyThread2 mt = new MyThread2();
        //创建3个线程，模拟三个窗口卖票
        Thread th1=new Thread(mt,"winOne");
        Thread th2=new Thread(mt,"winTwo");
        Thread th3=new Thread(mt,"winThree");
        th1.start();
        th2.start();
        th3.start();
    }
}
